package vn.hanelsoft.openwifi.model.adapter;

import java.util.ArrayList;

import vn.hanelsoft.openwifi.R;
import vn.hanelsoft.openwifi.common.UtilsCommon;
import vn.hanelsoft.openwifi.model.object.ObjectWifi;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class AdapterSpinner extends BaseAdapter {

	ArrayList<ObjectWifi> listWifi;
	Context mContext;

	public AdapterSpinner(Context mContext, ArrayList<ObjectWifi> listWifi) {
		this.mContext = mContext;
		this.listWifi = listWifi;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return listWifi.size();
	}

	@Override
	public Object getItem(int position) {
		return listWifi.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = convertView;
		final Holder holder;
		if (view == null) {
			LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
			view = inflater.inflate(R.layout.item_spinner, parent, false);

			holder = new Holder();
			holder.nameWifi = (TextView) view.findViewById(R.id.nameWifi);
			holder.nameWifi.setTypeface(UtilsCommon.getFontCustom(mContext));
			view.setTag(holder);
		} else {
			holder = (Holder) view.getTag();
		}

		final ObjectWifi mObjectWifi = (ObjectWifi) getItem(position);
		holder.nameWifi.setText(mObjectWifi.getWifiSSID());
		return view;
	}

	class Holder {
		TextView nameWifi;
	}
}
